package com.hellogood.yaohuo.server.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.hellogood.yaohuo.server.db.DBConnection;
import com.hellogood.yaohuo.server.db.DBHelper;
import com.hellogood.yaohuo.shared.entity.GoodsOrg;

public class GoodsOrgDAO extends DBHelper {
	Logger log = Logger.getLogger(this.getClass());

	@Override
	public List<?> initializeObject(ResultSet rs) throws SQLException {
		List<GoodsOrg> list = new ArrayList<GoodsOrg>();
		if (rs != null) {
			while (rs.next()) {
				GoodsOrg g = new GoodsOrg();
				g.setPluCode(rs.getString("pluCode"));
				g.setOrgCode(rs.getString("orgCode"));
				g.setPrice(rs.getBigDecimal("price"));
				g.setjPrice(rs.getBigDecimal("jPrice"));
				g.setgCount(rs.getInt("gCount"));
				g.setcCount(rs.getInt("cCount"));
				g.setCost(rs.getBigDecimal("cost"));
				g.setTotal(rs.getBigDecimal("total"));
				g.setTzAmount(rs.getBigDecimal("tzAmount"));
				g.setoJprice(rs.getBigDecimal("oJprice"));
				g.sethJprice(rs.getBigDecimal("hJprice"));
				g.setlJprice(rs.getBigDecimal("lJprice"));
				list.add(g);
			}
		}
		return list;
	}

	@SuppressWarnings("unchecked")
	public List<GoodsOrg> getGoodsOrg(String pluCode, String orgCode) {
		String hxDbName = DBConnection.hxDbName;
		String sql = "SELECT pluCode,orgCode,price,jPrice,gCount,cCount,cost,total,tzAmount,oJprice,hJprice,lJprice FROM " + hxDbName + "..GoodsOrg WHERE pluCode = '" + pluCode + "' AND orgCode = '"
				+ orgCode + "'";
		List<?> list = super.query(sql);
		return (List<GoodsOrg>) list;
	}
}
